package com.xtedu.examproject.entity;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.Map;

import java.io.Serializable;

public class ExamQuestion implements Serializable {
    private Integer id;
    private String title;
    private String option;
    private String answer;
    private int typeId;
    private int courseId;
    private boolean state;
    // 联表字段
    private String typeName;
    private String courseName;

    public ExamQuestion(int id, String title, String option, String answer, int typeId, int courseId, boolean state) {
        this.id = id;
        this.title = title;
        this.option = option;
        this.answer = answer;
        this.typeId = typeId;
        this.courseId = courseId;
        this.state = state;
        this.typeName = "";
        this.courseName = "";
    }

    public ExamQuestion() {
    }

    public int getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getOption() {
        return option;
    }

    public void setOption(String option) {
        this.option = option;
    }

    public String getAnswer() {
        return answer;
    }

    public void setAnswer(String answer) {
        this.answer = answer;
    }

    public int getTypeId() {
        return typeId;
    }

    public void setTypeId(int typeId) {
        this.typeId = typeId;
    }

    public int getCourseId() {
        return courseId;
    }

    public void setCourseId(int courseId) {
        this.courseId = courseId;
    }

    public boolean isState() {
        return state;
    }

    public void setState(boolean state) {
        this.state = state;
    }

    public String getTypeName() {
        return typeName;
    }

    public void setTypeName(String typeName) {
        this.typeName = typeName;
    }

    public String getCourseName() {
        return courseName;
    }

    public void setCourseName(String courseName) {
        this.courseName = courseName;
    }

    @Override
    public String toString() {
        return "ExamQuestion [id=" + id + ", title=" + title + ", option=" + option + ", answer=" + answer + ", typeId=" + typeId + ", courseId=" + courseId + ", state=" + state + "]";
    }

    public Map<String, String> getOptionMap() {
        try {
            ObjectMapper mapper = new ObjectMapper();
            return mapper.readValue(this.option, Map.class);
        } catch (Exception e) {
            return Map.of(); // 返回空Map
        }
    }
}
